// pages/outputSingleVoteResult/outputSingleVoteResult.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        voteID: '', // 当前投票的ID
        blockHeight:0,//区块高度
        transactionId:''//交易ID
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const voteID = options.voteID // 通过页面路径参数获取投票ID
        this.setData({
          voteID:voteID
        })
        let that = this
        wx.request({
          url: 'https://www.intohash.com/vote_backend/vote/queryVoteDetail/'+that.data.voteID,
          method:'GET',
          data: {
            "userId": wx.getStorageSync('userid'),
            "voteId": that.data.voteID
          },
          success:function (res) {
            console.log('查询区块链信息成功')
            console.log(res)  // 控制台输出服务端返回的结果
            that.setData({
              blockHeight:res.data.data.voteDetails[0].voteBlockChain.blockHeight,
              transactionId:res.data.data.voteDetails[0].voteBlockChain.transactionId
            })
            wx.setStorageSync('blockHeight', res.data.data.voteDetails[0].voteBlockChain.blockHeight)
            wx.setStorageSync('transactionId', res.data.data.voteDetails[0].voteBlockChain.transactionId)
          },
          fail:function(res) {
            console.log(res)
            wx.showToast({
              title: '查询区块链信息失败',
              icon: 'none'
            })
          }
    })
    },
    jumpToVote() {
      wx.redirectTo({       // 自动跳转到参与投票页面
        url: '/pages/vote/vote?voteID=' + this.data.voteID,
      })
    }
})
